
***********************************************************************************************
******************************creat ownership relation table*************************************************************
import delimited "H:\FAME\FAME OWNERSHIP- Oxford\MK_FAME_OWNERSHIP_TP.csv", clear
rename bvd_id identifier
browse related_ctry rel_id_country if related_ctry!=rel_id_country&rel_id_country!=""&rel_id_country!="WW"&rel_id_country!="YY"&rel_id_country!="ZZ"
tab sub_level

bysort id related_ctry: egen wholly_owned=max(wo)
keep type related_ctry id wholly_owned
rename wholly_owned wo
duplicates drop

rename related_ctry alpha2code
merge m:1 alpha2code using  "${hmrc_datadir}\CBT\ISO_countrycode.dta"
keep if _merge==3
drop _merge
destring identifier, ignore ("#,*,-") replace
save "${hmrc_datadir}\ownership2\mergedctry", replace
********************************************************************************************
********************************************************************************************
import delimited "H:\FAME\FAME OWNERSHIP- Oxford\MK_FAME_OWNERSHIP_TP.csv", clear
save "${hmrc_datadir}\ownership2\ownership2", replace
keep type bvd_id
duplicates drop
duplicates tag bvd_id, gen (tag)
tab tag
drop if tag!=0
drop tag
rename bvd_id identifier
destring identifier, ignore ("#,*,-") replace
save "${hmrc_datadir}\ownership2\duplicatestypedropped", replace
